import React, { Component } from "react";
import { Link, Route, Switch } from "react-router-dom";

class Hot extends Component {
  render() {
    return <div>这是hot页面</div>;
  }
}
class Wait extends Component {
  render() {
    return <div>这是Wait页面</div>;
  }
}

class Home extends Component {
  render() {
    console.log(this.props);
    const { path } = this.props.match;
    return (
      <>
        <div>这是home页面</div>
        <ul>
          <li>
            <Link to={`${path}/hot`}>热映</Link>
          </li>
          <li>
            <Link to={`${path}/wait`}>待映</Link>
          </li>
        </ul>

        <hr />

        <Switch>
          <Route path={`${path}/hot`} component={Hot}></Route>
          <Route path={`${path}/wait`} component={Wait}></Route>
        </Switch>
      </>
    );
  }
}
class About extends Component {
  render() {
    return <div>这是about页面</div>;
  }
}

class App extends Component {
  state = {};
  render() {
    return (
      <>
        <h2>嵌套路由</h2>
        <ul>
          <li>
            <Link to="/home">首页</Link>
          </li>
          <li>
            <Link to="/about">关于页</Link>
          </li>
        </ul>

        <hr />

        {/* 当一个路由有子路由的时候，不能添加exact属性 */}
        <Switch>
          <Route path="/home" component={Home}></Route>
          <Route path="/about" component={About} exact></Route>
        </Switch>
      </>
    );
  }
}

export default App;
